package com.demo.controller;

import com.demo.domain.SysDict;
import com.demo.service.SysDictService;
import com.demo.utils.AjaxResult;
import com.demo.utils.BaseController;
import com.demo.utils.PageUtils;
import com.demo.utils.TableDataInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gxd
 * @since 2025/5/28
 */
@RestController
@RequestMapping("/dict")
@Api(tags = "字典信息")
public class SysDictController extends BaseController {

    @Autowired
    private SysDictService dictService;

    @ApiOperation("分页列表-字典列表")
    @PostMapping("/pageList")
    public TableDataInfo pageList(@ApiParam(value = "字典查询条件", required = false) SysDict dict) {
        PageUtils.startPage(dict.getPageNum(), dict.getPageSize());
        List<SysDict> dictList = dictService.pageList(dict);
        return getDataTable(dictList);
    }

    @ApiOperation("不分页列表-字典列表")
    @PostMapping("/list")
    public AjaxResult list(@ApiParam(value = "字典查询条件", required = false) @RequestBody SysDict dict) {
        return success(dictService.selectDictList(dict));
    }

    @ApiOperation("详情信息-根据Id获取字典详情信息")
    @ApiImplicitParam(name = "id", value = "字典Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/getById/{id}")
    public AjaxResult getById(@PathVariable(value = "id") Long id) {
        return success(dictService.getDictById(id));
    }

    @ApiOperation("添加或修改-字典信息")
    @PostMapping("/addOrEdit")
    public AjaxResult addOrEdit(@ApiParam(value = "字典实体", required = true) @Valid @RequestBody SysDict dict) {
        return success(dictService.addOrEdit(dict));
    }

    @ApiOperation("删除-字典信息（支持批量）")
    @ApiImplicitParam(name = "ids", value = "字典Id（多个需逗号分隔）", required = true, allowMultiple = true, dataType = "String", paramType = "path")
    @DeleteMapping("/removeById")
    public AjaxResult removeById(@RequestParam(value = "ids") String ids) {
        return toAjax(dictService.batchRemoveById(ids));
    }

    @ApiOperation("修改状态-启用或禁用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "字典Id", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "Integer", paramType = "path")
    })
    @GetMapping("/editStatus")
    public AjaxResult editStatus(@RequestParam(value = "id") Long id, @RequestParam(value = "status") Integer status) {
        return toAjax(dictService.editStatus(id, status));
    }

    @ApiOperation("树查询-字典树")
    @GetMapping("/getDictTree")
    public AjaxResult getDictTree() {
        return success(dictService.getDictTree());
    }
}
